package com.lecture.java8.mvel;

import com.greenpineyu.fel.Expression;
import com.greenpineyu.fel.FelEngine;
import com.greenpineyu.fel.FelEngineImpl;
import com.greenpineyu.fel.context.FelContext;
import com.greenpineyu.fel.interpreter.Interpreter;
import com.greenpineyu.fel.parser.FelNode;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * @author luyn
 * @version 1.0
 * @description
 * @date 2020/8/25 19:22
 */
public class FelTest {
    public static void main(String[] args) throws InterruptedException, NoSuchFieldException, IllegalAccessException {
        FelEngine fel = new FelEngineImpl();
        fel.addFun(new AbsFunction());
        FelContext ctx = fel.getContext();

        String expression = "(abs(abs(99)) > 9 && absr(abs(99)) < 10) || current(\"tagname\", #time) > 10";


        String pattern = "(\\(abs\\(abs\\(\\d\\d\\)\\)).+ (absr\\(abs\\(\\d\\d\\)).+ (current\\(\\\"\\w+\\\".+\\#\\w+\\))";

        Pattern r = Pattern.compile(pattern);

        Matcher matcher = r.matcher(expression);
        while (matcher.find()) {
            System.out.println(matcher.group());
        }
        for (int i = 0; i < 100; i++) {
            if (!matcher.find()) {
                break;
            }
            System.out.println(matcher.group(i));
        }
        /*String expression = "TCODE_1598319038854 > 50000 && TCODE_1598319040669 < 10000";

        FelContext ctx = fel.getContext();
        ctx.set("TCODE_1598319040669", 789999990L);
        ctx.set("TCODE_1598319038854", 2);
        ctx.set("TCODE_1598319038854", 2000000000);
        ctx.set("TCODE_1598319038834", 2000000000);
        //728796505

        Object eval = fel.eval(expression);*/
        /*Object fsdfsdf = fel.compile("TCODE_1598319038854 > 99", ctx).eval(ctx);
        System.out.println(fsdfsdf) ;


        System.out.println(LocalDateTime.now());*/
       /* System.out.println("--");
        Thread.sleep(7000L);
        System.out.println(Math.abs(0));*/



                
       /* Class cache = Integer.class.getDeclaredClasses()[0]; //1
        Field myCache = cache.getDeclaredField("cache"); //2
        myCache.setAccessible(true);//3
        
        Integer[] newCache = (Integer[]) myCache.get(cache); //4
        newCache[132] = newCache[133]; //5

        int a = 2;
        int b = a + a;
        System.out.printf("%d + %d = %d", a, a, b); //*/

    }
}
